#!/usr/bin/perl

use strict;
use warnings;

use Template;

my $tt = Template->new;

my $base = "Mangos::DB::Characters";

open TABLES, "tables.txt";

while (<TABLES>) {
   chomp;
   my $name = $_;
   $_ =~ s/\b(\w)/\u$1/g;
   $_ =~ s/_(\w)/\u$1/g;
   my $bigname = $_;
   my %data = (
      big_name => $bigname,
      name => $name,
      base => $base
   );
   $tt->process("make.tt",\%data,'tempbase.pl');
   $tt->process("make_manager.tt",\%data,'tempmanager.pl');
   
   open INFILE, "<", "tempmanager.pl";   
   my $manager_contents = do { local $/; <INFILE> };
   
   my $output = `perl tempbase.pl`;
   open OUTFILE, ">", "$bigname.pm";
   print OUTFILE "$output\n$manager_contents";
   close OUTFILE;
}

close TABLES;
unlink("tempbase.pl");
unlink("tempmanager.pl");

